const service = require('../request').service;
const model = require("../../utils/modelUtil");

/**
 * 告示牌类
 */
class Notice {
    constructor(user) {
        this.user = user;
    }

    /**
     * 获取公告牌事件
     * @returns {Promise<unknown>}
     */
    getNoticeEvent() {
        return new Promise((resolve, reject) => {
            service({
                method: 'POST',
                url: this.user.game.reqUrl + '/GetBigMapSpecialEvent',
                data: model.userModel('GetBigMapSpecialEvent', {}, this.user.game.isWeb, this.user.game.data),
            }).then(res => {
                const resData = res.data;
                resolve(resData.code===200?resData.MsgData:{});
            }).catch(err => {
                reject(err);
            })
        })
    }

    /**
     * 刷新
     * @param type 0=免费 1=金条
     * @returns {Promise<unknown>}
     */
    refreshNotice(type) {
        return new Promise((resolve, reject) => {
            service({
                method: 'POST',
                url: this.user.game.reqUrl + '/refreshNotice',
                data: model.userModel('refreshNotice', {type: type}, this.user.game.isWeb, this.user.game.data),
            }).then(res => {
                const resData = res.data;
                resolve(resData.code===200?resData.MsgData:{});
            }).catch(err => {
                reject(err);
            })
        })
    }

    /**
     * 获取公告牌奖励
     * @param typeID 1000=宝箱 1008=押镖
     * @param eventID 事件ID
     * @returns {Promise<unknown>}
     */
    getNoticeAward(typeID, eventID) {
        return new Promise((resolve, reject) => {
            service({
                method: 'POST',
                url: this.user.game.reqUrl + '/GetNoticeAward',
                data: model.userModel('GetNoticeAward', {typeID: typeID, eventID: eventID}, this.user.game.isWeb, this.user.game.data),
            }).then(res => {
                const resData = res.data;
                resolve(resData.code===200?resData.MsgData:{});
            }).catch(err => {
                reject(err);
            })
        })
    }

    /**
     * 获取奇人异事奖励
     * @param adventureID 0
     * @param award 1
     * @param eventID 0
     * @returns {Promise<unknown>}
     */
    getRandEventAward(adventureID, award, eventID) {
        return new Promise((resolve, reject) => {
            service({
                method: 'POST',
                url: this.user.game.reqUrl + '/GetRandomEventAward',
                data: model.userModel('GetRandomEventAward', {adventureID: adventureID, award: award, eventID: eventID}, this.user.game.isWeb, this.user.game.data),
            }).then(res => {
                const resData = res.data;
                resolve(resData.code===200?resData.MsgData:{});
            }).catch(err => {
                reject(err);
            })
        })
    }

    /**
     * 获取四大恶人奖励
     * @param eventID 事件ID
     * @returns {Promise<unknown>}
     */
    getVillainAward(eventID) {
        const data = {
            eventID: eventID,
            typeID: 1009,
            flag: 1,
            npcIDArr: ["1004", "1005","1006","1007","1008","1010","1011","1012","1015","1017","1019","1020","1023","1024","1025","1026","1030","1035","1037","1038","1039","1040","1041","1042","1043","1044","1046","1048","310002","310004","310005","310008","310009"]
        }
        return new Promise((resolve, reject) => {
            service({
                method: 'POST',
                url: this.user.game.reqUrl + '/GetvillainAward',
                data: model.userModel('GetvillainAward', data, this.user.game.isWeb, this.user.game.data),
            }).then(res => {
                const resData = res.data;
                resolve(resData.code===200?resData.MsgData:{});
            }).catch(err => {
                reject(err);
            })
        })
    }
}

module.exports = Notice;